package cn.lili.modules.grab.xdxt.reps.goods;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class GoodsCateReps {

    private int code;
    private String msg;
    private List<Category> result;
    private String traceId;


    @Data
    public static class Category {
        @ApiModelProperty("分类id")
        private int id;
        @ApiModelProperty("分类图标路径")
        private String img;
        @ApiModelProperty("分类名称")
        private String name;
        @ApiModelProperty("上级分类id，-1表示根目录")
        private int supId;
    }

    /**
     * 将JSON构建为ListGoodsReps
     *
     * @param jsonString 值
     */
    public static GoodsCateReps builderGoodsCateReps(JSONObject jsonString) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        GoodsCateReps goodsCateReps = mapper.readValue(jsonString.toString(), GoodsCateReps.class);
        return goodsCateReps;
    }
}
